package com.ideaplugin.datamanager.config;

import lombok.extern.slf4j.Slf4j;
import org.dromara.x.file.storage.core.FileInfo;
import org.dromara.x.file.storage.core.UploadPretreatment;
import org.dromara.x.file.storage.core.aspect.FileStorageAspect;
import org.dromara.x.file.storage.core.aspect.UploadAspectChain;
import org.dromara.x.file.storage.core.platform.FileStorage;
import org.dromara.x.file.storage.core.recorder.FileRecorder;
import org.springframework.stereotype.Component;

/**
 * 使用切面打印文件上传和删除的日志
 */
@Slf4j
@Component
public class LogFileStorageAspect implements FileStorageAspect {

    /**
     * 上传，成功返回文件信息，失败返回 null
     */
    @Override
    public FileInfo uploadAround(UploadAspectChain chain, FileInfo fileInfo, UploadPretreatment pre, FileStorage fileStorage, FileRecorder fileRecorder) {
        fileInfo = chain.next(fileInfo, pre, fileStorage, fileRecorder);
        //final HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        //自动获取domain
        //final String path = request.getRequestURL().toString().replace(request.getRequestURI(), "") + "/" + fileInfo.getBasePath() + fileInfo.getPath();
        //fileInfo.setUrl(path + fileInfo.getFilename());
        //if (StringUtils.isNotBlank(fileInfo.getThFilename())) {
        //    fileInfo.setThUrl(path + fileInfo.getThFilename());
        //}
        return fileInfo;
    }


}
